package org.example;

import com.google.common.collect.Lists;
import org.example.bo.TestUserBO;

import java.util.List;
import java.util.Random;

/**
 * @author azraelee
 */
public class Test {

    public static void main(String[] args) {
        BalancePlusTree<Integer, TestUserBO> balancePlusTree = new BalancePlusTree<>();

        List<Integer> keyList = Lists.newArrayList(1,96,97,98,99);

        for (int i = 0; i < keyList.size(); i++) {
            TestUserBO testUserBO = new TestUserBO();
            testUserBO.setId(keyList.get(i));
            testUserBO.setName(getRandomString(5));
            testUserBO.setDept((long) new Random().nextInt(1000));
            balancePlusTree.insertOrUpdate(testUserBO.getId(), testUserBO);

        }
        long start1 = System.nanoTime();
        System.out.println("初始化插入数据耗时：" + (System.nanoTime() - start1)+ "纳秒");
        for (int i = 2; i < 95; i++) {
            TestUserBO testUserBO = new TestUserBO();
            testUserBO.setId(i);
            testUserBO.setName(getRandomString(5));
            testUserBO.setDept((long) new Random().nextInt(1000));
            balancePlusTree.insertOrUpdate(testUserBO.getId(), testUserBO);
        }
        balancePlusTree.print();

    }

    public static String getRandomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
